LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

CopyData(Byte[],Int32) Method

Example 





Buffer containing the image new data.
Offset into data where the copy operation should begin.
Updates the data of this RasterImage. .NET support Silverlight support WinRT support
Syntax
public void CopyData( 
   byte[] data,
   int dataOffset
)
'Declaration
 
Public Overloads Sub CopyData( _
   ByVal data() As Byte, _
   ByVal dataOffset As Integer _
) 
'Usage
 
Dim instance As RasterImage
Dim data() As Byte
Dim dataOffset As Integer
 
instance.CopyData(data, dataOffset)
public void CopyData( 
   byte[] data,
   int dataOffset
)
 function Leadtools.RasterImage.CopyData(Byte[],Int32)( 
   data ,
   dataOffset 
)
public:
void CopyData( 
   array<byte>^ data,
   int dataOffset
) 

Parameters

data
Buffer containing the image new data.
dataOffset
Offset into data where the copy operation should begin.
Remarks

The byte array that you specify will be copied.

The data is copied as is into the internal memory of this RasterImage.

Example
 
Public Sub CopyDataExample()
      Dim codecs As RasterCodecs = New RasterCodecs()
      Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"))

      Dim data As Byte() = New Byte(image.BytesPerLine * image.Height - 1) {}
      Dim val As Integer = 0
      Dim x As Integer = 0
      Do While x < data.Length
         data(x) = CByte(val)
         val += 1
         If val > 255 Then
            val = 0
         End If
         x += 1
      Loop
      image.CopyData(data, 0)

      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "CopyData.bmp"), RasterImageFormat.Bmp, 0)

      image.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void CopyDataExample()
   {
      RasterCodecs codecs = new RasterCodecs();
      RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"));

      byte[] data = new byte[image.BytesPerLine * image.Height];
      int val = 0;
      for(int x = 0; x < data.Length; x++)
      {
         data[x] = (byte)val;
         val++;
         if(val > 255)
            val = 0;
      }
      image.CopyData(data, 0);

      codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "CopyData.bmp"), RasterImageFormat.Bmp, 0);

      image.Dispose();
      codecs.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterImageExamples.prototype.CopyDataExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {

         var codecs = new RasterCodecs();
         var srcFileName = "Assets\\Image1.cmp";
         var image;

         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
            .then(function (img) {
               image = img;

               var data = new Array(image.bytesPerLine * image.height);
               var val = 0;

               for (var x = 0; x < data.length; x++) {
                  data[x] = val;
                  val++;
                  if (val > 255)
                     val = 0;
               }
               image.copyData(data, 0);

               return Tools.AppLocalFolder().createFileAsync("CopyData.bmp")
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);
               return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 0)
            })
            .then(function () {
               image.close();
               codecs.close();
            });
      }
   }
}
[TestMethod]
public async Task CopyDataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   byte[] data = new byte[image.BytesPerLine * image.Height];
   int val = 0;
   for (int x = 0; x < data.Length; x++)
   {
      data[x] = (byte)val;
      val++;
      if (val > 255)
         val = 0;
   }
   image.CopyData(data, 0);

   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("CopyData.bmp");
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 0);

   image.Dispose();
   codecs.Dispose();
}
public void CopyDataExample(RasterImage image, Stream destStream)
{
   byte[] data = new byte[image.BytesPerLine * image.Height];
   int val = 0;
   for (int x = 0; x < data.Length; x++)
   {
      data[x] = (byte)val;
      val++;
      if (val > 255)
         val = 0;
   }
   image.CopyData(data, 0);
   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Png, 0);

   image.Dispose();
}
Public Sub CopyDataExample(ByVal image As RasterImage, ByVal destStream As Stream)
   Dim data As Byte() = New Byte(image.BytesPerLine * image.Height - 1){}
   Dim val As Integer = 0
   Dim x As Integer = 0
   Do While x < data.Length
      data(x) = CByte(val)
      val += 1
      If val > 255 Then
         val = 0
      End If
      x += 1
   Loop
   image.CopyData(data, 0)
   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Png, 0)

   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterImage Class
RasterImage Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.